# sharedfs-pingpong - a demo to illustrate SkyPilot's bucket mounting feature.
#
# This program implements coordination between processes using a shared file
# system they can access. Each process reads data from <process-id>.txt, prints
# it, and writes to <process-id + 1>.txt. This creates a synchronization between
# processes where process i continues only after process i-1 has written its
# output.
#
# Usage:
#   sky launch -c pingpong pingpong.yaml

name: pingpong

num_nodes: 2

resources:
  cloud: gcp

file_mounts:
    /sharedfs:
        name: sky-sharedfs-romilbgcs
        mode: MOUNT
        store: gcs

setup: |
  rm -rf sharedfs-pingpong
  git clone https://github.com/romilbhardwaj/sharedfs-pingpong.git

run: |
  num_nodes=`echo "$SKYPILOT_NODE_IPS" | wc -l`
  python -u sharedfs-pingpong/main.py --process-id ${SKYPILOT_NODE_RANK} --shared-path /sharedfs/ --num-processes $num_nodes
